<template>
    <el-upload
    :action="`${$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/smis`"
    :headers="{token: $cookie.get('token')}"
    accept=".hmap,.xmap,.vmap,.zip,.dae"
    :limit="2"
    :on-preview="(file, fileList) => { preview((file.response && file.response.url) || file.url)}"
    :on-success="(response, file, fileList) => {
      filePath = (file.response && file.response.url) || file.url
    }"
    :on-exceed="(files, fileList) =>{
      $message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
    }"
    :on-remove="(file, fileList) => {
      // $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
      //  $message.success(data.msg)
      // })
      filePath = ''
    }"
    :file-list="files"
    >
    <el-button size="small" type="primary">点击上传</el-button>
    <div slot="tip" class="el-upload__tip">支持上传hmap,xmap,vmap,zip格式地图</div>
  </el-upload>
</template>
<script>
  import Vue from 'vue'
  import * as JFMAP from './hmap.manage.js'
  import axios from 'axios'
  export default {
    name: "MapUpload",
    data () {
        return {
            filePath: ""
        };
    },
    props: {
      value: {
        type: String,
        default: () => { return null }
      }
    },
    computed: {
      files: {
        get () {
          if (!this.filePath) {
            return []
          }
          var obj=this.filePath.lastIndexOf("/")
          var fileName = this.filePath.substr(obj+1)
          return [{name: fileName, url: this.filePath}]
        }
      }
    },
    watch:{
      value (val) {
        this.filePath = val
      },
      filePath (val) {
        this.$emit('input', val)
      }
    },
    methods: {
      preview(url) {
        console.log("preview:"+url)
        this.$emit("preview", url)
      },
      checkMeasure (file) {
        return true
      }
    }
  };
</script>
